package com.niit.spark.rdd.test

import org.apache.spark.{SparkConf, SparkContext}

/**
 * Date:2025/5/9
 * Author：Ys
 * Description:
 */
object ReduceByKeyExercise {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("ReduceByKeyExercise")
    val sc = new SparkContext(sparkConf)
    sc.setLogLevel("ERROR")
    val salesRDD = sc.parallelize(Seq(("ProductA", 100.5), ("ProductB", 200.8),
      ("ProductA", 150.2), ("ProductC", 300.0), ("ProductB", 95.3)))

    val salesByProduct = salesRDD.reduceByKey(_+_)

    salesByProduct.collect().foreach(println)

    sc.stop()
  }

}
